<template>
  <view>
    <button>data.time:{{time}}</button>
    <button>load.time:{{loadTime}}</button>
    <button @click="viewOut">out</button>
    <button @click="viewLocal">local</button>
    <button @click="viewDialog">dialog</button>
    <button @click="viewHttp">http</button>
    <uni-popup ref="popup" type="center" background-color="#fff">
      <view>123123</view>
      <web-view src="https://www.baidu.com" :update-title="false" :webview-styles="styles"></web-view>
      <view>aaaaa</view>
    </uni-popup>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        time: new Date().toLocaleString(),
        loadTime: "",
        styles: {
          width: '90%',
          height: '50%',
          left: '5%',
          // top: '150px',
          // right: '50px'
        }
      }
    },
    onLoad() {
      this.loadTime = new Date().toLocaleString()
    },
    methods: {
      viewOut() {
        uni.navigateTo({
          url: "/pages/webview/out"
        })
      },
      viewLocal() {
        uni.downloadFile({
          url: 'https://zjjcmspublic.oss-cn-hangzhou-zwynet-d01-a.internet.cloud.zj.gov.cn/jcms_files/jcms1/web3087/site/attach/0/a676a8d89d9a49658c97eb68a89f4704.pdf',
          success: (res) => {
            if (res.statusCode === 200) {
              //下载成功，得到文件临时地址
              console.log('下载成功', res.tempFilePath);
              console.log('\n');
              console.log('完整返回', JSON.stringify(res))
              console.log('\n');
              
              // #ifdef H5
              let newUrl = res.tempFilePath
              // #endif

              //条件编译，若为App端，则需要将本地文件系统URL转换为平台绝对路径	
              // #ifdef APP-PLUS
              let newUrl = plus.io.convertLocalFileSystemURL(res.tempFilePath)
             
             // newUrl 这个地址，每次下载以后都不一样，中间有段时间戳
             // 要保持一致，就先下载下来，然后saveFile 到某个固定位置
             // /storage/emulated/0/Android/data/io.dcloud.HBuilder/apps/HBuilder/doc/uniapp_temp_1763536164462/download/a676a8d89d9a49658c97eb68a89f4704.pdf
              
              // #endif
               console.log('本地地址', newUrl);
              //这里新建一个vue页面，跳转并预览pdf文档
              uni.navigateTo({
                url: "/pages/webview/local?url=" + newUrl,
              })

              
            }
          },
          fail: (error) => {
            console.log('下载失败', error)
          }
        })

        // uni.navigateTo({
        //   url: "/pages/webview/local"
        // })
      },
      viewDialog() {
        this.$refs.popup.open()
      },
      viewHttp() {
        uni.navigateTo({
          url: '/pages/webview/http'
        })
      }
    }
  }
</script>

<style>
</style>